package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CourseBan;
import com.ruoyi.course.service.ICourseBanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级Controller
 *
 * @author mac
 * @date 2023-03-11
 */
@RestController @RequestMapping("/course/courseBan") public class CourseBanController extends BaseController {
    @Autowired private ICourseBanService courseBanService;

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseBan:list')") @GetMapping("/list") public TableDataInfo list(
        CourseBan courseBan) {
        startPage();
        List<CourseBan> list = courseBanService.selectCourseBanList(courseBan);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @PreAuthorize("@ss.hasPermi('course:courseBan:export')") @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export") public void export(HttpServletResponse response, CourseBan courseBan) {
        List<CourseBan> list = courseBanService.selectCourseBanList(courseBan);
        ExcelUtil<CourseBan> util = new ExcelUtil<CourseBan>(CourseBan.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:courseBan:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(
        @PathVariable("id") Long id) {
        return AjaxResult.success(courseBanService.selectCourseBanById(id));
    }

    @GetMapping("/getPartNames") public AjaxResult getPartNames() {
        return AjaxResult.success(courseBanService.getPartNames());
    }

    /**
     * 新增班级
     */
    @PreAuthorize("@ss.hasPermi('course:courseBan:add')") @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping public AjaxResult add(@RequestBody CourseBan courseBan) {
        return toAjax(courseBanService.insertCourseBan(courseBan));
    }

    /**
     * 修改班级
     */
    @PreAuthorize("@ss.hasPermi('course:courseBan:edit')") @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping public AjaxResult edit(@RequestBody CourseBan courseBan) {
        return toAjax(courseBanService.updateCourseBan(courseBan));
    }

    /**
     * 删除班级
     */
    @PreAuthorize("@ss.hasPermi('course:courseBan:remove')") @Log(title = "班级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}") public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(courseBanService.deleteCourseBanByIds(ids));
    }
}
